/*
 * @Author: your name
 * @Date: 2021-02-26 09:22:44
 * @LastEditTime: 2021-02-26 14:18:33
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \web-app\vue.config.js
 */
const path = require('path')

const resolve = dir => path.join(__dirname, dir)

module.exports = {
  productionSourceMap: false,
  chainWebpack: (config) => {
    const svgRule = config.module.rule('svg')
    // const terser = config.optimization.minimizer('terser')
    svgRule.uses.clear()
    // GraphQL Loader
    svgRule
      .test(/\.svg$/)
      .include.add(resolve('./src/assets/icons'))
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
    config.module
      .rule('images')
      .test(/\.(png|jpe?g|gif|webp|svg)(\?.*)?$/)
      .exclude.add(resolve('./src/assets/icons'))
  },
  css: {
    loaderOptions: {
      sass: {
        // 这里的选项会传递给 sass-loader进行全局预处理样式
        prependData: '@import "@/assets/styles/_variables.scss";'
      }
    }
  },
  devServer: {
    proxy: { // 配置跨域
      '/api': {
        target: 'http://localhost:3000', // 这里后台的地址模拟的;应该填写你们真实的后台接口
        ws: true,
        changOrigin: true, // 允许跨域
        pathRewrite: {
          '^/api': '' // 请求的时候使用这个api就可以
        }
      }
    }
  }
}